<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
  // https://www.cnblogs.com/ranyonsue/p/11201730.html
    function Animal(name){
      this.name = name || '动物',
      this.sum = function(){
        console.log(this.name)
      }
    }
    Animal.prototype.age= 10
    //原型链继承 继承单一，无法向父类构造函数传参，属性共享·
    function Cat(){
      this.name = 'cat'
    }
    Cat.prototype = new Animal()
    var cat1 = new Cat()

    // 构造函数继承 无法对构造函数的服用，无法继承父类的原型属性
    function Dog(){
      Animal.call(this,'dog')
    }
    let dog1 = new Dog()
    console.log(dog1.name)

    //组合继承 调用了俩次父类构造函数，子类的工造函数代替了父类的构造函数
    function Dusk(name){
      Animal.call(this,name)
    }
    Dusk.prototype = new Animal()
    let dusk1 = new Dusk('dusk')
    console.log(dusk1.name)
    
    //原型是继承
    //就是objectcreate
    function ctreate(obj){
      function F(){}
      F.prototype = obj
      return new F()
    }
    //寄生继承
    function subobject(obj){
      var sub = Object.create(obj)
      sub.name = 'gar'
      return sub
    }
    let ani = new Animal()
    let sub2 = subobject(ani)
    console.log(sub2)
    //寄生组合继承
    function create1(obj){
      function F(){}
      F.prototype = obj
      return new F()
    }
    var con = create1(Animal.prototype)
    function Sub(){
      Animal.call(this)
    }
    Sub.prototype = con
    con.constructor = Sub
    var sub1 = new Sub()
    console.log(sub1.age)
  </script>
</body>
</html>